<template>
  <div class="carouselFigure">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item
        v-for="(item, index) in carouselUrl"
        :key="index"
        @click="toDetailsPage(item)"
      >
        <img :src="item.imgUrl" alt="" />
      </van-swipe-item>
    </van-swipe>
  </div>
</template>
 <script>
import { getCarousel } from "../../../api/index-api";
export default {
  name: "CarouselFigure",
  data() {
    return {
      carouselUrl: null,
    };
  },
  methods: {
    toDetailsPage(data){
      if(data.type==="article"){
        this.$router.push({
          path:'/SharePage?id='+data.id
        })
      }else{
         this.$router.push({
          path:'/DetailsLayOut?id='+data.id
        })
      }
    }
  },
  created() {
    //   请求轮播图数据
    getCarousel().then((res) => {
      console.log(res)
      this.carouselUrl = res.data;
    });
  },
};
</script>
 <style scoped lang="less">
.my-swipe .van-swipe-item {
  text-align: center;
  width: 100%;
  height: auto;
  img{
      width: 100%;
  }
}
.carouselImg {
  width: 100%;
}
</style>
